package com.bjpowernode.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

//将RestHighLevelClient注册为Bean交给spring进行管理
@Component
public class SearchConfig {

    //从配置文件中获取主机地址和端口号
    @Value("${elasticsearch.host}")
    String host;
    @Value("${elasticsearch.port}")
    int port;

    @Bean
    public RestHighLevelClient getRestHighLevelClient(){
        return new RestHighLevelClient(RestClient.builder(new HttpHost(host,port,"http")));
    }
}
